﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace Maticsoft.Web.OrderInfo
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int OId=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(OId);
				}
			}
		}
			
	private void ShowInfo(int OId)
	{
		Maticsoft.BLL.OrderInfo bll=new Maticsoft.BLL.OrderInfo();
		Maticsoft.Model.OrderInfo model=bll.GetModel(OId);
		this.lblOId.Text=model.OId.ToString();
		this.txtMemberId.Text=model.MemberId.ToString();
		this.txtODate.Text=model.ODate.ToString();
		this.txtOMoney.Text=model.OMoney.ToString();
		this.chkIsPay.Checked=model.IsPay;
		this.txtTableId.Text=model.TableId.ToString();
		this.txtDiscount.Text=model.Discount.ToString();

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(!PageValidate.IsNumber(txtMemberId.Text))
			{
				strErr+="MemberId格式错误！\\n";	
			}
			if(!PageValidate.IsDateTime(txtODate.Text))
			{
				strErr+="ODate格式错误！\\n";	
			}
			if(!PageValidate.IsDecimal(txtOMoney.Text))
			{
				strErr+="OMoney格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtTableId.Text))
			{
				strErr+="TableId格式错误！\\n";	
			}
			if(!PageValidate.IsDecimal(txtDiscount.Text))
			{
				strErr+="Discount格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int OId=int.Parse(this.lblOId.Text);
			int MemberId=int.Parse(this.txtMemberId.Text);
			DateTime ODate=DateTime.Parse(this.txtODate.Text);
			decimal OMoney=decimal.Parse(this.txtOMoney.Text);
			bool IsPay=this.chkIsPay.Checked;
			int TableId=int.Parse(this.txtTableId.Text);
			decimal Discount=decimal.Parse(this.txtDiscount.Text);


			Maticsoft.Model.OrderInfo model=new Maticsoft.Model.OrderInfo();
			model.OId=OId;
			model.MemberId=MemberId;
			model.ODate=ODate;
			model.OMoney=OMoney;
			model.IsPay=IsPay;
			model.TableId=TableId;
			model.Discount=Discount;

			Maticsoft.BLL.OrderInfo bll=new Maticsoft.BLL.OrderInfo();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
